package net.tailfish.starter.common.log;

import org.apache.commons.lang3.StringUtils;

import java.text.Normalizer;
import java.util.Arrays;
import java.util.List;

/**
 * @PackageName net.tailfish.starter.common.log
 * @ClassName LoggerUtils
 * @Author tailFish
 * @Date Created in 9:55 2021/5/28
 * @Description 日志过滤
 */
public class LoggerUtils {

    private static final String[] replaceChars = {"\r","\n","%0A","%0a","%0D","%0d","\b","\t","\f"};

    public static Object[] logFilter(Object... params){

        if(null == params){
            return null;
        }

        for (int i = 0;i < params.length;i++){
            if(params[i] instanceof String){
                params[i] = logFilter((String) params[i]);
            }
        }

        return params;
    }


    public static String logFilter(String param){
        if(StringUtils.isBlank(param)){
            return null;
        }

        List<String> suChars = Arrays.asList(replaceChars);

        String encoder = Normalizer.normalize(param, Normalizer.Form.NFKC);

        for(String suChar: suChars){
            encoder = encoder.replaceAll(suChar,"");
        }

        return encoder;
    }
}
